<!DOCTYPE html>
<html>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	    <title>运动会管理系统</title>
	    <link rel="stylesheet" href="../layui/css/layui.css">
	</head>
	<body>
		<form class="layui-form" action="">
		 
		  <div class="layui-form-item">
		    <label class="layui-form-label">队编号</label>
		    <div class="layui-input-inline">
		      <input type="text" id="tno" name="tno" required lay-verify="required" placeholder="请输入编号" autocomplete="off" class="layui-input">
		    </div>
		    
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">队名</label>
		    <div class="layui-input-inline">
		      <input type="text" id="tn" name="tn" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
		    </div>
		    
		  </div>
		  					 		  
		  
		  <div class="layui-form-item">
		      <label class="layui-form-label">项目名称</label>
		      <div class="layui-input-block">
		        <select id = "cnA" name="cnA" lay-verify="required">
		          
		        </select>
		      </div>
		    </div>
			
			<div class="layui-form-item">
			  <label class="layui-form-label">名次</label>
			  <div class="layui-input-inline">
			    <input type="text" id="rank" name="rank" required lay-verify="required" placeholder="请输入名次" autocomplete="off" class="layui-input">
			  </div>
			 </div>
			  
			  <div class="layui-form-item">
			    <label class="layui-form-label">成绩</label>
			    <div class="layui-input-inline">
			      <input type="text" id="score" name="score" required lay-verify="required" placeholder="请输入成绩" autocomplete="off" class="layui-input">
			    </div>
			</div>
			
		  <div class="layui-form-item">
		    <div class="layui-input-block">
		      <button class="layui-btn" lay-submit lay-filter="addAth">立即提交</button>
		      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		  </div>
		</form>
		 
		<script src="../layui/layui.js"></script>
		<script>
		//Demo
		layui.use(['form','layer'] ,function(){
		  var form = layui.form;
		  var layer = layui.layer;
		  var $ = layui.$;
		  var form = layui.form;
		  
		  //加载项目名称列表
		  $.getJSON("http://localhost:8080/complistT",function(d){
			  if(d.code!=0){
				  layer.msg(d.msg);
			  }else{
				  var list = d.data;
				  var str ="<option value=''></option>";
				  for(var i =0;i<list.length;i++){
					  str+="<option value=\""+list[i].cnoA+"\">"+list[i].cnA+"</option>";
				  }
				  $("#cnA").html(str);
				  form.render('select');
			  }
		  });
		  //监听提交
		  form.on('submit(addAth)', function(data){
			console.log("->",data);  
		    layer.msg(JSON.stringify(data.field));
			//AJAX请求
			$.post("http://localhost:8080/editScoreT",data.field,function(d){
				console.log(d);
				if(d!=true){
					layer.msg(d);
				}else{
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index); //再执行关闭
				}
			}
			
			);
			//取消form默认的action
		    return false;
		  });
		});
		</script>					      	    
		
	</body>
</html>
